package com.xiaolin.designmode.composite.lucency;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName Composite
 * @Description 树枝构件角色
 * @Detail detail
 * @Author MyPC
 * @Date 2020/11/4
 * @Version 1.0
 */
public class Composite implements Component {
    private List<Component> contain=new ArrayList<>();
    public void add(Component component) {
        contain.add(component);
    }
    public void remove(Component component) {
        contain.remove(component);
    }
    public Component getChildren(int index) {
        return contain.get(index);
    }

    @Override
    public void operation() {
        for (Component component : contain) {
            component.operation();
        }
    }
}
